package com.easy.frame.common.mq.rabbit.deadLetter;

import com.easy.frame.common.mq.rabbit.RabbitConstants;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 监听死信队列，超过重试次数之后就会来到死信队列中
 * 失败的队列，做人工补偿
 *
 * @author gll
 * 2019/5/6 17:25
 */
@Component
@RabbitListener(queues = {RabbitConstants.Queue.EF_DEADLETTER_QUEUE}, ackMode = "MANUAL")
public class RabbitDeadLetterListener {

    @RabbitHandler
    @Transactional(rollbackFor = Exception.class)
    public void receive(String event) {
        //这里接收到异常消费的消息，可以做回滚，或者记录日志，以保证数据的最终一致性。
        System.out.println("dead-letter:" + event);
    }
}
